

*setup directories


 
 	 
 global output = "$FA_datasets"
  

global data09 = "$wave2009" 
global data10 = "$wave2010"
global data11 = "$wave2011"
global data13 = "$wave2013"
 
 
 
 
 
 
 
**1. SET UP PARCELS IN ALL ROUNDS FIRST
** SECTIONS 2A (PARCEL DATA OWNED, parcel_owned=1) AND 2B (WITH USER RIGHTS, parcel_owned=0)
{
*************************
**Set up 2009-10 data*****
**************************
cd "$data09"

*use "AGSEC1.dta", clear

*sort HHID

*save  "$output/tempfiles/temp2a_2009.dta", replace

**measures of property rights linked to questions 6,7,8,9 (distance matters, see JDS reference)
use "AGSEC2A.dta", clear
gen parcel_id=a2aq2
gen parcel_own=1
gen parcel_size_gps=a2aq4
gen parcel_size_farmer=a2aq5
drop a2aq*
sort HHID
*merge m:1 HHID using "$output/tempfiles/temp2a_2009.dta"
*drop _merge
save  "$temp/temp2a_2009.dta", replace

use "AGSEC2B.dta", clear
gen parcel_id=a2bq2
gen parcel_own=0
gen parcel_size_gps=a2bq4
gen parcel_size_farmer=a2bq5
drop a2bq* 
append using "$temp/temp2a_2009.dta"
 label values parcel_own parcel_code
 
save  "$temp/temp2_2009.dta", replace

erase "$temp/temp2a_2009.dta"



*************************
**Set up 2010-11 data*****
**************************

cd "$data10"
*use "AGSEC1.dta", clear

*sort HHID

*save  "$output/tempfiles/temp2a_2010.dta", replace

use "AGSEC2A.dta", clear
gen parcel_id=prcid
gen parcel_own=1
gen parcel_size_gps=a2aq4
gen parcel_size_farmer=a2aq5
 
drop a2aq*
sort HHID
*merge m:1 HHID using "$output/tempfiles/temp2a_2010.dta"
*drop _merge
save  "$temp/temp2a_2010.dta", replace

use "AGSEC2B.dta", clear
gen parcel_id=prcid
gen parcel_own=0
gen parcel_size_gps=a2bq4
gen parcel_size_farmer=a2bq5

drop a2bq* 
append using "$temp/temp2a_2010.dta"
*label define parcel_code  0 "User Rights" 1 "Owned"
label values parcel_own parcel_code
*lab define parcel_acq_code 1 "Purchased" 2 "Inherited or gift" 3 "Leased-in" 4 "Just walked in" 5 "DK" 6 "Other" 7 "Agreement w/ owner" 8 "No Agreement w/ owner"
save  "$temp/temp2_2010.dta", replace

erase "$temp/temp2a_2010.dta"



**************************
**Set up 2011-12 data*****
**************************

cd "$data11"
*use "AGSEC1.dta", clear

*sort HHID

*save  "$output/tempfiles/temp2a_2011.dta", replace

***PARCEL DATA OWNED AND WITH USER RIGHTS
use "AGSEC2A.dta", clear
gen parcel_id=parcelID
gen parcel_own=1
gen parcel_size_gps=a2aq4
gen parcel_size_farmer=a2aq5
drop a2aq* 
sort HHID
save  "$temp/temp2a_2011.dta", replace

use "AGSEC2B.dta", clear
gen parcel_id=parcelID
gen parcel_own=0
gen parcel_size_gps=a2bq4
gen parcel_size_farmer=a2bq5
drop a2bq* 

append using "$temp/temp2a_2011.dta"
*label define parcel_code  0 "User Rights" 1 "Owned"
label values parcel_own parcel_code
save  "$temp/temp2_2011.dta", replace

erase "$temp/temp2a_2011.dta"

**************************
**Set up 2013-14 data*****
**************************

cd "$data13"
*use "AGSEC1.dta", clear

*sort HHID

*save  "$output/tempfiles/temp2a_2013.dta", replace

***PARCEL DATA OWNED AND WITH USER RIGHTS
use "AGSEC2A.dta", clear
gen parcel_id=parcelID
gen parcel_own=1
gen parcel_size_gps=a2aq4
gen parcel_size_farmer=a2aq5
drop a2aq* 
sort HHID
*merge m:1 HHID using "$output/tempfiles/temp2a_2013.dta"
*drop _merge
save  "$temp/temp2a_2013.dta", replace

use "AGSEC2B.dta", clear
gen parcel_id=parcelID
gen parcel_own=0
gen parcel_size_gps=a2bq4
gen parcel_size_farmer=a2bq5

drop a2bq* A2B*

append using "$temp/temp2a_2013.dta"
*label define parcel_code  0 "User Rights" 1 "Owned"
label values parcel_own parcel_code

save  "$temp/temp2_2013.dta", replace
erase "$temp/temp2a_2013.dta"
}



**2.Merge by round and create comparable housheold id (hhid)
******************************************************
{
	cd "$temp"
use "temp2_2009.dta", clear
sort HHID parcel_id   
gen surveyround=1
 gen hhid=HHID
 destring HHID, replace
  format HHID  %15.0f
save "agric2009.dta", replace


use "temp2_2010.dta", clear
sort HHID parcel_id  
gen surveyround=2
 gen hhid=HHID
 destring HHID, replace
save "agric2010.dta", replace

use "temp2_2011.dta", clear
sort HHID parcel_id  
gen surveyround=3
 format HHID %15.0f
tostring HHID, generate(hhid) usedisplayformat force
 save "agric2011.dta", replace

 
use "temp2_2013.dta", clear
sort HHID parcel_id 
gen surveyround=4
drop HHID
ren hh hhid
save "agric2013.dta", replace
}

 use agric2009, clear
	append using agric2010, force
	append using agric2011, force
	append using agric2013, force

save "$FA_datasets/data_landarea", replace

